<?php
/**
 * (exporter) EU备货品类(国家)
 */
namespace App\Exporter\Stocking;

use App\Models\Product\ProductClassify;
use App\Models\SsBasic\CountrySkuEstimate;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class CountrySkuExporter extends ExcelExporter implements WithMapping,WithHeadings
{

    protected $fileName = 'EU备货品类(国家).csv';

    public function headings(): array{

        $head1 = ['国家','品类','季节性'];
        $head2 = [];
        for ($i = 0; $i < CountrySkuEstimate::ESTIMATE_NUM; $i++){
            $head2[] = date('y/m',strtotime("midnight first day of $i month")).'预估';
        }

        return array_merge($head1,$head2);
    }

    /**
     * 导出字段参数
     * @param mixed $model
     * @return array
     */
    public function map($model) : array{

        $data1 = [
            $model->country->country ?? '',
            $model->classify->title ?? '',
            ProductClassify::$_season[$model->classify->season] ?? '',
        ];

        $data2 = [];
        for ($i = 0; $i < CountrySkuEstimate::ESTIMATE_NUM; $i++){
            $data2[] = $model->estimate_num.$i ?: 0;
        }

        $count = 0;
        $data = [];
        $data[$count] = array_merge($data1,$data2);

        return $data;
    }

}
